package com.ruoyi.yl.receptionManage.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yl.receptionManage.vo.YlVisitReservationVo;
import com.ruoyi.yl.receptionManage.service.IYlVisitReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 参观预约Controller
 *
 * @author Ming
 * @date 2025-10-21
 */
@Api(tags = "参观预约Controller")
@RestController
@RequestMapping("/pg/visitReservation")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class YlVisitReservationController extends BaseController {

    private final IYlVisitReservationService ylVisitReservationService;

    @ApiOperation("查询参观预约列表")
    @GetMapping("/list")
    public TableDataInfo<YlVisitReservationVo> list(YlVisitReservationVo entity) {
        return ylVisitReservationService.queryList(entity);
    }

    @ApiOperation("查询参观预约所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(YlVisitReservationVo entity) {
        return AjaxResult.success("查询成功", ylVisitReservationService.queryAll(entity));
    }

    @ApiOperation("导出参观预约列表")
    @Log(title = "参观预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlVisitReservationVo entity) {
        List<YlVisitReservationVo> list = ylVisitReservationService.queryAll(entity);
        ExcelUtil<YlVisitReservationVo> util = new ExcelUtil<>(YlVisitReservationVo.class);
        util.exportExcel(response, list, "参观预约数据");
    }

    @ApiOperation("获取参观预约详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", ylVisitReservationService.queryById(id));
    }

    @ApiOperation("新增参观预约")
    @Log(title = "参观预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlVisitReservationVo entity) {
        return toAjax(ylVisitReservationService.save(entity));
    }

    @ApiOperation("修改参观预约")
    @Log(title = "参观预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlVisitReservationVo entity) {
        return toAjax(ylVisitReservationService.updateById(entity));
    }

    @ApiOperation("删除参观预约")
    @Log(title = "参观预约", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ylVisitReservationService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
